package icu.javacg.storage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import icu.javacg.storage.pojo.Warehouse;
import icu.javacg.storage.service.WarehouseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@Tag(name = "仓库管理接口-张宏俊")
@RestController
public class WarehouseController {
    @Autowired
    private WarehouseService warehouseService;

    @GetMapping("/hello")
    @Operation(summary = "查看所有仓库")
    public List<Warehouse> select() {
        return warehouseService.selectAll();

    }
    @Operation(summary = "添加一个仓库")
    @PutMapping("/hello1")
    public String inserts(Warehouse warehouse){
        int insert = warehouseService.insert(warehouse);
        return insert==1?"添加成功":"添加失败";
    }


    @Operation(summary = "根据id删除仓库")
    @DeleteMapping("/hello3")
    public String deletebyid(int id) {
        int delete = warehouseService.delete(id);

        return delete == 1 ? "删除成功" : "删除失败";
    }
    @PostMapping("/hello6")//
    @Operation(summary = "根据id修改厂库信息的管理人员信息")
    public String postbyid(Warehouse warehouses){
        int i = warehouseService.updataWarehouse(warehouses);
        return i==1?"修改成功":"修改失败";
    }
    @Operation(summary = "查看一个管理员管理多少仓库")//
    @GetMapping("/hello5")
    public List<Warehouse> getname(String name) {
        List<Warehouse> warehouses = warehouseService.selcetName(name);
        System.out.println(warehouses.size());
        if (warehouses.size() == 0) {
            Warehouse warehouse = new Warehouse(0, "抱歉没有这个人", "", 0, "请输入正确的名字");
            warehouses.add(warehouse);
        }

        return warehouses;
    }


//    @Operation(summary = "分页查看仓库数据")
//    @GetMapping("/page")
//    public Page<Warehouse> selectPages(int a,int b){
//
//    return warehouseService.MybatisPlugin(a, b);
//}
//    @Operation(summary = "添加仓库")
//    @PutMapping("/hello")
//    public String inserts(Warehouse warehouse){
//        int insert = warehouseService.insert(warehouse);
//        return insert==1?"添加成功":"添加失败";
//    }
//
//    @Operation(summary = "查看仓库为空的仓库")
//    @GetMapping("/hello2")
//    public  List<Warehouse> selectnull(){
//
//        return warehouseService.listnull();
//    }
//    @Operation(summary = "根据id删除仓库")
//    @DeleteMapping("/hello3")
//    public  String deletebyid(int id){
//        int delete = warehouseService.delete(id);
//        return delete == 1 ? "删除成功":"删除失败" ;
//    }
//
//    @Operation(summary = "查看容积最大的仓库")
//    @GetMapping ("/hello4")
//    public  List<Warehouse> selectbybat(){
//        List<Warehouse> warehouses = warehouseService.selectMax();
//
//        return warehouses;
//    }
//
//    @Operation(summary = "查看一个管理员管理多少仓库")//
//    @GetMapping ("/hello5")
//    public  List<Warehouse> getname(String name){
//        List<Warehouse> warehouses = warehouseService.selcetName(name);
//        System.out.println(warehouses.size());
//        if(warehouses.size()==0){
//            Warehouse warehouse = new Warehouse(0, "抱歉没有这个人", "", 0, "请输入正确的名字");
//            warehouses.add(warehouse);
//        }
//
//        return warehouses;
//    }
//
//    @PostMapping("/hello6")//
//    @Operation(summary = "根据id修改厂库信息")
//    public String postbyid(Warehouse warehouses){
//        int i = warehouseService.updataWarehouse(warehouses);
//        return i==1?"修改成功":"修改失败";
//    }


}
